<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- coordinates.qdoc -->
  <title>Concepts - Visual Coordinates in Qt Quick | Qt Quick 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquick-index.html">Qt Quick</a></td><td >
			概念 - Qt Quick 中的视觉坐标</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#item-coordinates">Item Coordinates</a></li>
<li class="level1"><a href="#scene-coordinates">Scene Coordinates</a></li>
<li class="level1"><a href="#worked-example">Worked Example</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">概念 - Qt Quick 中的视觉坐标</h1>
<span class="subtitle"></span>
<!-- $$$qtquick-visualcanvas-coordinates.html-description -->
<div class="descr"> <a name="details"></a>
<a name="item-coordinates"></a>
<h2 id="item-coordinates"><span lang="zh-cn">项</span>坐标</h2>
<p>Qt Quick 中使用的默认视觉坐标系统是项目坐标。这是一个笛卡尔坐标系，(0,0) 位于项目的左上角。x 轴向右增长，y 轴向下增长，因此项目的右下角位于坐标（宽度，高度）处。</p>
<p>单个项目的位置是根据其父项的坐标系指定的。这意味着从非同级项读取 x,y 值可能需要进行转换以将它们转换为相同的坐标系。发生这种情况时，场景坐标通常用作中间坐标系。</p>
<a name="scene-coordinates"></a>
<h2 id="scene-coordinates">场景坐标</h2>
<p>场景坐标是 (0,0) 对应于当前正在渲染场景的窗口左上角的坐标。场景坐标通常与窗口中根项的项坐标相同。</p>
<p>您可以使用您感兴趣的项目坐标系上的函数将项目转换为场景坐标。请参阅<a href="file:///E:/_Personal/Qt5.12-Document-Trans-in-Chinese/qtquick/qml-qtquick-item.html#mapFromItem-method">Item::mapFromItem</a>和<a href="file:///E:/_Personal/Qt5.12-Document-Trans-in-Chinese/qtquick/qml-qtquick-item.html#mapToItem-method">Item::mapToItem</a>以转换为场景坐标或其他项目的坐标。</p>
<a name="worked-example"></a>
<h2 id="worked-example">工作示例</h2>
<p>下面的 QML 代码创建了一个正方形排列，并添加了点以识别点：</p>
<pre class="cpp">

  Rectangle {
      width: <span class="number">200</span>
      height: <span class="number">200</span>
      color: <span class="string">&quot;red&quot;</span>

      Rectangle {
          x: <span class="number">100</span>
          y: <span class="number">100</span>
          width: <span class="number">100</span>
          height: <span class="number">100</span>
          color: <span class="string">&quot;blue&quot;</span>

          Rectangle {
              width: <span class="number">50</span>
              height: <span class="number">50</span>
              color: <span class="string">&quot;green&quot;</span>
          }
      }
  }

</pre>
<p class="centerAlign"><img src="images/visual-coordinates-example.png" alt="" /></p><p>在此图像中，黑点位于红色矩形项目坐标内的 (0,0) 处。如果红色矩形是场景的根项，那么黑点也将位于场景坐标中的 (0,0) 处。</p>
<p>蓝色矩形位于白点 (100,100) 处，相对于红色矩形的左上角。</p>
<p>绿色矩形没有指定 x,y，所以它的位置默认为 (0,0)。因为它位于其父级蓝色矩形的坐标中的 (0,0)，所以它位于该矩形的左上角。这与红色矩形坐标中 (100,100) 处的白点相同。</p>
</div>
<!-- @@@qtquick-visualcanvas-coordinates.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
